<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Class template rbtree_best_fit</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_interprocess_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp" title="Header &lt;boost/interprocess/mem_algo/rbtree_best_fit.hpp&gt;">
<link rel="prev" href="mapped_region/advice_types.html" title="Type advice_types">
<link rel="next" href="simple_seq_fit.html" title="Class template simple_seq_fit">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mapped_region/advice_types.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_interprocess_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="simple_seq_fit.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.interprocess.rbtree_best_fit"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template rbtree_best_fit</span></h2>
<p>boost::interprocess::rbtree_best_fit</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../boost_interprocess_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp" title="Header &lt;boost/interprocess/mem_algo/rbtree_best_fit.hpp&gt;">boost/interprocess/mem_algo/rbtree_best_fit.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> MutexFamily<span class="special">,</span> <span class="keyword">typename</span> VoidPointer<span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> MemAlignment<span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="rbtree_best_fit.html" title="Class template rbtree_best_fit">rbtree_best_fit</a> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// <a class="link" href="rbtree_best_fit.html#boost.interprocess.rbtree_best_fittypes">types</a></span>
  <span class="keyword">typedef</span> <span class="identifier">MutexFamily</span>                                                   <a class="link" href="rbtree_best_fit.html#boost.interprocess.rbtree_best_fit.mutex_family"><span class="identifier">mutex_family</span></a><span class="special">;</span>         
  <span class="keyword">typedef</span> <span class="identifier">VoidPointer</span>                                                   <a name="boost.interprocess.rbtree_best_fit.void_pointer"></a><span class="identifier">void_pointer</span><span class="special">;</span>           <span class="comment">// Pointer type to be used with the rest of the Interprocess framework. </span>
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>                                                   <a name="boost.interprocess.rbtree_best_fit.multiallocation_chain"></a><span class="identifier">multiallocation_chain</span><span class="special">;</span>
  <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">intrusive</span><span class="special">::</span><span class="identifier">pointer_traits</span><span class="special">&lt;</span> <span class="identifier">char_ptr</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">difference_type</span> <a name="boost.interprocess.rbtree_best_fit.difference_type"></a><span class="identifier">difference_type</span><span class="special">;</span>      
  <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_unsigned</span><span class="special">&lt;</span> <span class="identifier">difference_type</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span>                 <a name="boost.interprocess.rbtree_best_fit.size_type"></a><span class="identifier">size_type</span><span class="special">;</span>            

  <span class="comment">// <a class="link" href="rbtree_best_fit.html#boost.interprocess.rbtree_best_fitconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="rbtree_best_fit.html#idp56561952-bb"><span class="identifier">rbtree_best_fit</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="rbtree_best_fit.html#idp56563088-bb"><span class="special">~</span><span class="identifier">rbtree_best_fit</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="rbtree_best_fit.html#idp56546480-bb">public member functions</a></span>
  <span class="keyword">void</span> <span class="special">*</span> <a class="link" href="rbtree_best_fit.html#idp56546688-bb"><span class="identifier">allocate</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idp56547680-bb"><span class="identifier">deallocate</span></a><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idp56548720-bb"><span class="identifier">get_size</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idp56549360-bb"><span class="identifier">get_free_memory</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idp56550016-bb"><span class="identifier">zero_free_memory</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idp56550800-bb"><span class="identifier">grow</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idp56551856-bb"><span class="identifier">shrink_to_fit</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="rbtree_best_fit.html#idp56552496-bb"><span class="identifier">all_memory_deallocated</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="rbtree_best_fit.html#idp56553168-bb"><span class="identifier">check_sanity</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> 
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">*</span><span class="special">,</span> <span class="keyword">bool</span> <span class="special">&gt;</span> 
    <a class="link" href="rbtree_best_fit.html#idp56553888-bb"><span class="identifier">allocation_command</span></a><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">,</span> 
                       <span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="special">&amp;</span><span class="special">,</span> <span class="identifier">T</span> <span class="special">*</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span> <span class="keyword">void</span> <span class="special">*</span><span class="special">,</span> <span class="keyword">bool</span> <span class="special">&gt;</span> 
  <a class="link" href="rbtree_best_fit.html#idp56556656-bb"><span class="identifier">raw_allocation_command</span></a><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">,</span> 
                         <span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">*</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idp56559504-bb"><span class="identifier">size</span></a><span class="special">(</span><span class="keyword">const</span> <span class="keyword">void</span> <span class="special">*</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <span class="special">*</span> <a class="link" href="rbtree_best_fit.html#idp56560512-bb"><span class="identifier">allocate_aligned</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="rbtree_best_fit.html#idp56563296-bb">public static functions</a></span>
  <span class="keyword">static</span> <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idp56563504-bb"><span class="identifier">get_min_size</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// public data members</span>
  <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">size_type</span> <span class="identifier">PayloadPerAllocation</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idp75693328"></a><h2>Description</h2>
<p>This class implements an algorithm that stores the free nodes in a red-black tree to have logarithmic search/insert times. </p>
<div class="refsect2">
<a name="idp75693792"></a><h3>
<a name="boost.interprocess.rbtree_best_fittypes"></a><code class="computeroutput">rbtree_best_fit</code> 
        public
       types</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p>
<span class="keyword">typedef</span> <span class="identifier">MutexFamily</span> <a name="boost.interprocess.rbtree_best_fit.mutex_family"></a><span class="identifier">mutex_family</span><span class="special">;</span></p>
<p>Shared mutex family used for the rest of the Interprocess framework </p>
</li></ol></div>
</div>
<div class="refsect2">
<a name="idp75696848"></a><h3>
<a name="boost.interprocess.rbtree_best_fitconstruct-copy-destruct"></a><code class="computeroutput">rbtree_best_fit</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="idp56561952-bb"></a><span class="identifier">rbtree_best_fit</span><span class="special">(</span><span class="identifier">size_type</span> size<span class="special">,</span> <span class="identifier">size_type</span> extra_hdr_bytes<span class="special">)</span><span class="special">;</span></pre>
<p>Constructor. "size" is the total size of the managed memory segment, "extra_hdr_bytes" indicates the extra bytes beginning in the sizeof(rbtree_best_fit) offset that the allocator should not use at all. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="idp56563088-bb"></a><span class="special">~</span><span class="identifier">rbtree_best_fit</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Destructor. </li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp75703248"></a><h3>
<a name="idp56546480-bb"></a><code class="computeroutput">rbtree_best_fit</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <span class="special">*</span> <a name="idp56546688-bb"></a><span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_type</span> nbytes<span class="special">)</span><span class="special">;</span></pre>Allocates bytes, returns 0 if there is not more memory. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56547680-bb"></a><span class="identifier">deallocate</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> addr<span class="special">)</span><span class="special">;</span></pre>
<p>Deallocates previously allocated bytes </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">size_type</span> <a name="idp56548720-bb"></a><span class="identifier">get_size</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Returns the size of the memory segment. </li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">size_type</span> <a name="idp56549360-bb"></a><span class="identifier">get_free_memory</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Returns the number of free bytes of the segment. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56550016-bb"></a><span class="identifier">zero_free_memory</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Initializes to zero all the memory that's not in use. This function is normally used for security reasons. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56550800-bb"></a><span class="identifier">grow</span><span class="special">(</span><span class="identifier">size_type</span> extra_size<span class="special">)</span><span class="special">;</span></pre>
<p>Increases managed memory in extra_size bytes more </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56551856-bb"></a><span class="identifier">shrink_to_fit</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Decreases managed memory as much as possible. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="idp56552496-bb"></a><span class="identifier">all_memory_deallocated</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Returns true if all allocated memory has been deallocated. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="idp56553168-bb"></a><span class="identifier">check_sanity</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Makes an internal sanity check and returns true if success </p>
</li>
<li class="listitem"><pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> 
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">*</span><span class="special">,</span> <span class="keyword">bool</span> <span class="special">&gt;</span> 
  <a name="idp56553888-bb"></a><span class="identifier">allocation_command</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span> command<span class="special">,</span> 
                     <span class="identifier">size_type</span> limit_size<span class="special">,</span> <span class="identifier">size_type</span> preferred_size<span class="special">,</span> 
                     <span class="identifier">size_type</span> <span class="special">&amp;</span> received_size<span class="special">,</span> <span class="identifier">T</span> <span class="special">*</span> reuse_ptr <span class="special">=</span> <span class="number">0</span><span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span> <span class="keyword">void</span> <span class="special">*</span><span class="special">,</span> <span class="keyword">bool</span> <span class="special">&gt;</span> 
<a name="idp56556656-bb"></a><span class="identifier">raw_allocation_command</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span> command<span class="special">,</span> 
                       <span class="identifier">size_type</span> limit_object<span class="special">,</span> <span class="identifier">size_type</span> preferred_object<span class="special">,</span> 
                       <span class="identifier">size_type</span> <span class="special">&amp;</span> received_object<span class="special">,</span> <span class="keyword">void</span> <span class="special">*</span> reuse_ptr <span class="special">=</span> <span class="number">0</span><span class="special">,</span> 
                       <span class="identifier">size_type</span> sizeof_object <span class="special">=</span> <span class="number">1</span><span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">size_type</span> <a name="idp56559504-bb"></a><span class="identifier">size</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">void</span> <span class="special">*</span> ptr<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Returns the size of the buffer previously allocated pointed by ptr. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <span class="special">*</span> <a name="idp56560512-bb"></a><span class="identifier">allocate_aligned</span><span class="special">(</span><span class="identifier">size_type</span> nbytes<span class="special">,</span> <span class="identifier">size_type</span> alignment<span class="special">)</span><span class="special">;</span></pre>
<p>Allocates aligned bytes, returns 0 if there is not more memory. Alignment must be power of 2 </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp75756160"></a><h3>
<a name="idp56563296-bb"></a><code class="computeroutput">rbtree_best_fit</code> public static functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<pre class="literallayout"><span class="keyword">static</span> <span class="identifier">size_type</span> <a name="idp56563504-bb"></a><span class="identifier">get_min_size</span><span class="special">(</span><span class="identifier">size_type</span> extra_hdr_bytes<span class="special">)</span><span class="special">;</span></pre>Obtains the minimum size needed by the algorithm. </li></ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2005-2012 Ion Gaztanaga<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mapped_region/advice_types.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_interprocess_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="simple_seq_fit.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
